//
//  alertUtil.swift
//  万才信息App
//
//  Created by 陌上互联  on 16/7/14.
//  Copyright © 2016年 万才信息. All rights reserved.
//

import Foundation
import UIKit

//警告对话框
class warningAlertUtil {
    
    let title:String
    let msg:String
    let alert:UIAlertController
    let cancelAction:UIAlertAction
    
    init(title:String,msg:String){
        self.title=title
        self.msg=msg
        
        alert=UIAlertController(title: title, message: msg, preferredStyle: .Alert)
        cancelAction=UIAlertAction(title: "确定", style: .Cancel, handler: nil)
        alert.addAction(cancelAction)
    }
    
    func show(controller:UIViewController){
        controller.presentViewController(alert, animated: true, completion: nil)
    }
}

//等待对话框
class waitingAlertUtil {
    
    let waitingAlert:UIAlertController
    let spinner:UIActivityIndicatorView
    let msg:String
    
    init(msg:String){
        self.msg=msg+"\n\n"
        waitingAlert=UIAlertController(title: nil, message: self.msg, preferredStyle: .Alert)
        spinner=UIActivityIndicatorView(activityIndicatorStyle: .WhiteLarge)
        spinner.center=CGPointMake(130.5, 65.5)
        spinner.color=UIColor.blackColor()
        spinner.startAnimating()
        waitingAlert.view.addSubview(spinner)
    }
    
//    显示等待对话框
    func show(contorller:UIViewController){
        contorller.presentViewController(waitingAlert, animated: false, completion: nil)
    }
//    停止等待对话框
    func stop(){
        waitingAlert.dismissViewControllerAnimated(false, completion: nil)
    }
    
    
}